<?php

namespace backend\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\PayScoreItem;

/**
 * PayScoreItemSearch represents the model behind the search form about `backend\models\PayScoreItem`.
 */
class PayScoreItemSearch extends PayScoreItem
{
	public $username;
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'ex_id', 'log_id', 'admin_uid', 'admin_time', 'doing', 'send_time', 'deliver_time'], 'integer'],
            [['logistics_message', 'logistics_name', 'logistics_other_name', 'send_address', 'send_photo', 'accept_address', 'accept_photo'], 'safe'],
            [['logistice_price'], 'number'],
            [['username'],'string','max'=>30]
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = PayScoreItem::find()->joinWith(['itemInfo','exchangeInfo','logInfo.userInfo','adminInfo'])/*->orderBy('pay_score_item.id DESC')*/;

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'ex_id' => $this->ex_id,
            'log_id' => $this->log_id,
            'item_id' => $this->item_id,
            'number' => $this->number,
            'score' => $this->score,
            'logistics_state' => $this->logistics_state,
            'logistice_price' => $this->logistice_price,
            'admin_uid' => $this->admin_uid,
            'admin_time' => $this->admin_time,
            'doing' => $this->doing,
            'send_time' => $this->send_time,
            'deliver_time' => $this->deliver_time,
        ]);

        $query->andFilterWhere(['like', 'logistics_trade', $this->logistics_trade])
            ->andFilterWhere(['like', 'logistics_message', $this->logistics_message])
            ->andFilterWhere(['like', 'logistics_name', $this->logistics_name])
            ->andFilterWhere(['like', 'logistics_other_name', $this->logistics_other_name])
            ->andFilterWhere(['like', 'send_address', $this->send_address])
            ->andFilterWhere(['like', 'send_photo', $this->send_photo])
            ->andFilterWhere(['like', 'accept_address', $this->accept_address])
            ->andFilterWhere(['like', 'accept_photo', $this->accept_photo])
            ->andFilterWhere(['like', 'notes', $this->notes])
        	->andFilterWhere(['like', 'user_info.username', $this->username]);

        return $dataProvider;
    }
}
